/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package compile;

import net.openhft.compiler.CompilerUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author guoyha
 * @date 2022/8/24 11:14
 */
public class DynaCompTest {

    public static Map<String, Object> map = new HashMap<>();


    public static void main(String[] args) throws Exception {

        String code = "import java.util.HashMap;\n" +
                "import com.yunerp.web.vaadin.message.alert;\n" +
                "import java.util.List;\n" +
                "import java.util.ArrayList;\n" +
                "import java.util.Map;" +
                "\n" +
                "public class web2905763164651825363{\n" +
                " public  Object execute(Map<String,Object> param) {\n" +
                " System.out.println(param.get(\"key\")+ \"次测试编译\");" +
                "  return null;\n" +
                " }\n" +
                "}";
        String name = "web2905763164651825363";

        for (int i = 0; i < 100000; i++) {
            long time1 = System.currentTimeMillis();
            try {
                Class cl = CompilerUtils.CACHED_COMPILER.loadFromJava(name, code);
                if (cl == null) {
                    System.out.println("编译失败/类加载失败");
                    continue;
                }
                Map<String, Object> param = new HashMap<>();
                param.put("key", i);
            } catch (Exception e) {
                e.printStackTrace();
            }
            long time2 = System.currentTimeMillis();
            System.out.println("次数：" + i + "            time:" + (time2 - time1));
        }
    }

}
